package com.ymatou.iapi.godmch.testcase;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.iapi.godmch.parameter.CreateCodeBean;
import com.ymatou.iapi.godmch.parameter.bindRelationBean;
import com.ymatou.iapi.godmch.parameter.createIndepMchBean;
import com.ymatou.iapi.godmch.parameter.createagentBean;
import com.ymatou.iapi.godmch.parameter.createmchBean;
import com.ymatou.iapi.godmch.parameter.registerByCodeBean;
import com.ymatou.iapi.godmch.service.CreateCodeCall;
import com.ymatou.iapi.godmch.service.bindRelationCall;
import com.ymatou.iapi.godmch.service.createIndepMchCall;
import com.ymatou.iapi.godmch.service.createSupplierCodeCall;
import com.ymatou.iapi.godmch.service.createagentCall;
import com.ymatou.iapi.godmch.service.registerByCodeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.shenqi.GodmchManageCallService;
import com.ymttest.database.model.agent_type;
import com.ymttest.database.model.mch_relation;
import com.ymttest.database.sqlwapper.godmch.agent_typeWapper;
import com.ymttest.database.sqlwapper.godmch.country_infoWapper;
import com.ymttest.database.sqlwapper.godmch.invite_codeWapper;
import com.ymttest.database.sqlwapper.godmch.mch_infoWapper;
import com.ymttest.database.sqlwapper.godmch.mch_relationWapper;
/**
*独立云绑定商户关系
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_bindRelation{
	private static bindRelationBean bean;
	private static bindRelationCall call;
	
	agent_typeWapper agentTypeWapper=new agent_typeWapper();
	mch_infoWapper infoWapper=new mch_infoWapper();
	mch_relationWapper relationWapper=new mch_relationWapper();
	invite_codeWapper codeWapper=new invite_codeWapper();
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("独立云绑定商户关系");
	}

	@Before
	public void caseUp() {
		bean=new bindRelationBean();
		call=new bindRelationCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(call.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindRelation_001() {
		Logger.start(true,"独立云绑定商户关系-同一平台的独立云绑定渠道-返回成功");
		try {
			//1:独立商户1创建邀请码  2：独立商户1注册渠道
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(0).getAgentType());
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);

			//mchId2 渠道
            String code= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, code);
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
            
            bean.setMchId(registerByCodeCall.getRegMchId());
            bean.setCode(createCodeCall.getCode());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("200", call.getStatusCode1(), "验证status");
			//mch_relation
			mch_relation relation=relationWapper.selectByPrimaryKey(bean.getMchId(),mchId).get(0);
			Logger.verifyEquals(agenttypeList.get(0).getAgentType(), relation.getAgentType(), "验证AgentType");
			Logger.verifyEquals(1, relation.getAgentModel(), "验证AgentModel");
			Logger.verifyEquals(0, relation.getState(), "验证state");
			Logger.verifyEquals(true, relation.getSamePlatform(), "验证samePlatform");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindRelation_002() {
		Logger.start(true,"独立云绑定商户关系-不是同一平台的独立云绑定渠道-返回成功");
		try {
	           //mch_info中的PlatformMchId 对应独立商户平台Id
				//1:独立商户1创建邀请码  2：独立商户1注册渠道
				createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
	            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
	            Integer mchId=createIndepMchCall.getmchId();    
				//邀请码
				CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
				//查询类型
				agent_typeWapper agentTypewapper = new agent_typeWapper();
				Map<String, Object> map = new HashMap();
				map.put("mchId", mchId);
				List<agent_type> agenttypeList = agentTypewapper.selectby(map);
				createCodeBean.setRoleType(agenttypeList.get(0).getAgentType());
				CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);

				//mchId2
				createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
	            createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
	            Integer mchId2=createIndepMchCall.getmchId();  
	            
//	            String code= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
//	            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, code);
//	            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
	            
	            bean.setMchId(mchId2);
	            bean.setCode(createCodeCall.getCode());
				call.setData(bean);
				call.callService();				
			    Logger.verifyEquals("500", call.getStatusCode1(), "验证code");
				
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindRelation_003() {
		Logger.start(true,"独立云绑定商户关系-同一平台的独立云绑定主商户-返回失败-禁止绑定");
		try {
			//1:独立商户1创建邀请码  2：独立商户1注册渠道
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(0).getAgentType());
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
            
            bean.setMchId(mchId);
            bean.setCode(createCodeCall.getCode());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("500", call.getStatusCode1(), "验证status");		
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindRelation_004() {
		Logger.start(true,"独立云绑定商户关系-同一平台的独立云绑定分销小店-返回失败-禁止绑定");
		try {
			//1:独立商户1创建邀请码  2：独立商户1注册渠道
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
			createagentBean.setAgentMode(2);
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			//mchId2 渠道
            String code= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, code);
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
            
            bean.setMchId(registerByCodeCall.getRegMchId());
            bean.setCode(createCodeCall.getCode());
			call.setData(bean);
			call.callService();			
			
			Logger.verifyEquals("500", call.getStatusCode1(), "验证status");	
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindRelation_005() {
		Logger.start(true,"独立云绑定商户关系-同一平台的独立云绑定供货商-返回失败-禁止绑定");
		try {
			//1:独立商户1创建邀请码是分销小店  2：独立商户1注册渠道
			createIndepMchBean createIndepMchBean=GodmchManageCallService.InitCreateIndepMchBean();
            createIndepMchCall createIndepMchCall=GodmchManageCallService.CreateIndepMchCall(createIndepMchBean);
            Integer mchId=createIndepMchCall.getmchId();    
            createSupplierCodeCall createSupplierCodeCall=GodmchManageCallService.createSupplierCode(mchId);
			//邀请码
			CreateCodeBean createCodeBean=GodmchManageCallService.InitcreateCodeBeanForAgent(mchId, true);
			// 创建代理类型
			createagentBean createagentBean = GodmchManageCallService.InitCreateAgentTypeBean(mchId);
			createagentBean.setAgentMode(2);
			createagentCall createagentcall = GodmchManageCallService.CreateAgentTypeCall(createagentBean);
			
			//查询类型
			agent_typeWapper agentTypewapper = new agent_typeWapper();
			Map<String, Object> map = new HashMap();
			map.put("mchId", mchId);
			List<agent_type> agenttypeList = agentTypewapper.selectby(map);
			createCodeBean.setRoleType(agenttypeList.get(2).getAgentType());
			
			CreateCodeCall createCodeCall=GodmchManageCallService.createCodeCall(createCodeBean);
			//mchId2 渠道
            String code= GodmchManageCallService.getChannelPic(mchId).getInviteCode();
            registerByCodeBean registerByCodeBean=GodmchManageCallService.initRegisterByCode(mchId, code);
            registerByCodeCall registerByCodeCall=GodmchManageCallService.registerByCodeCall(registerByCodeBean);
            
            bean.setMchId(registerByCodeCall.getRegMchId());
            bean.setCode(createSupplierCodeCall.getCode());
			call.setData(bean);
			call.callService();				
			
			Logger.verifyEquals("500", call.getStatusCode1(), "验证status");	
			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindRelation_006() {
		Logger.start(true,"独立云绑定商户关系-mchId不存在-返回失败");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindRelation_007() {
		Logger.start(true,"独立云绑定商户关系-mchId为空-返回失败");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindRelation_008() {
		Logger.start(true,"独立云绑定商户关系-code不存在-返回失败");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_bindRelation_009() {
		Logger.start(true,"独立云绑定商户关系-code为空-返回失败");
		try {
			//TODO 补全case代码
			org.junit.Assert.fail();
			call.setData(bean);
			call.callService();			
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}